<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:12}">
            <a-form-item label="考区">
              <a-input placeholder="请输入..." v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:12}">
            <a-form-item label="备注">
              <a-input placeholder="请输入..." v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" style="text-align:center">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleAdd">添加</a-button>
              <a-button type="primary" @click="handleExport">导出</a-button>
              <a-button type="primary" @click="handleBatchDel">批量删除</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
      :scroll="{ x: 1500 }"
    >
    <template slot="action" slot-scope="text,record">
        <a @click="handleDel(record)">删除</a>
      </template>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>

    <ets-add :etsAddVisiable="etsAddVisiable" @close="handleAddClose" @success="handleAddSuccess" ></ets-add>
    </a-card>
</div>
</template>

<script>
import EtsAdd from './etsAdd.vue'
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    EtsAdd
  },
  data () {
    return {
      etsAddVisiable: false,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx'
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '名称',
          dataIndex: 'mc'
        },
        {
          title: '备注',
          dataIndex: 'bz'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      selectMenu: {
        yx: [] // 院系
      },
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 加载数据
    loadData () {
      return new Promise(resolve => { resolve() }).then(res => {
        this.data = [{
          mc: '大中华',
          bz: '不错的校区',
          key: 1
        }, {
          mc: '大中华',
          bz: '不错的校区',
          key: 15
        }, {
          mc: '大中华',
          bz: '不错的校区',
          key: 17
        }]
      })
    },
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleExport () {
      console.log('导出')
    },
    // 删除
    handleDel () {
      console.log('删除')
    },
    // 批量删除
    handleBatchDel () {
      console.log('批量删除')
    },
    // 添加
    handleAdd () {
      console.log('添加')
      this.etsAddVisiable = true
    },
    // 关闭添加弹层
    handleAddClose () {
      this.etsAddVisiable = false
    },
    // 添加成功
    handleAddSuccess () {
      this.etsAddVisiable = false
      this.$message.success('添加成功')
    },
    // 改变时间
    handleDateChange () {

    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
